#ifndef CONFIG_HPP_INCLUDED
#define CONFIG_HPP_INCLUDED

#include "global.hpp"

#include <map>
#include <iosfwd>
#include <vector>
#include <boost/variant/variant.hpp>
#include <boost/exception/exception.hpp>

#include "game_errors.hpp"

class config;

class config
{
	static config invalid;

	void check_valid() const;

public:
	config();

	explicit config(const std::string& child);

	operator bool() const
	{
		return this != &invalid;
	}

	typedef std::vector<config*> child_list;
	typedef std::map<std::string, child_list> child_map;



	config& child(const std::string& key, int n = 0);

	const config& child(const std::string& key, int n = 0) const
	{
		return const_cast<config*>(this)->child(key, n);
	}

	struct error : public game::error, public boost::exception
	{
		error(const std::string& message) : game::error(message) {}
	};

private:
	child_map children;
};

#endif
